package com.a2j.web.car.controller;

import com.a2j.beans.base.BaseBean;
import com.a2j.beans.base.BasePageBean;
import com.a2j.beans.base.code.ResponseCode;
import com.a2j.beans.car.series.CarSeriesDTO;
import com.a2j.beans.car.series.CarSeriesPagesBO;
import com.a2j.beans.car.series.CarSeriesVO;
import com.a2j.web.car.service.CarSeriesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Author: bzb
 * Data: 2022/1/14 22:43
 * Desc: 车系controller
 */
@RestController
@RequestMapping("/carSeries")
@Api(tags = "车系")
public class CarSeriesController {

    @Resource
    CarSeriesService service;

    /**\
     * 新增车系
     * @param record 对象
     * @return 新增对象
     */
    @PostMapping("/addCarSeries")
    @ApiOperation(value = "添加车系")
    @ApiImplicitParams({})
    public BaseBean<String> addCarSeries(@RequestBody CarSeriesDTO record) {
        service.addCarSeries(record);
        return BaseBean.success(ResponseCode.SUCCESS);
    }

    /**
     * 删除车系
     * @param id 车系id
     */
    @DeleteMapping("/delCarSeries")
    @ApiOperation(value = "删除车系")
    @ApiImplicitParam(name = "id", value = "车系id", dataType = "int", required = true, defaultValue = "1")
    public BaseBean<String> delCarSeries(@RequestParam Integer id) {
        service.delCarSeries(id);
        return BaseBean.success(ResponseCode.SUCCESS);
    }

    /**
     * 开关
     * @param id 车系id
     * @param enable 0:关闭 1:打开
     */
    @PutMapping("/enable")
    @ApiOperation(value = "车系开关")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "品牌id", dataType = "int", required = true, defaultValue = "1"),
            @ApiImplicitParam(name = "enable", value = "开关状态  0:关 1:开", dataType = "int", defaultValue = "0")
    })
    public BaseBean<String> enable(@RequestParam Integer id, @RequestParam Integer enable) {
        service.enable(id, enable);
        return BaseBean.success(ResponseCode.SUCCESS);
    }

    /**
     * 更新车系信息
     * @param record 车系信息
     */
    @PutMapping("/updateInfo")
    @ApiOperation(value = "更新车系信息")
    @ApiImplicitParams({})
    public BaseBean<String> updateInfo(@RequestBody CarSeriesVO record) {
        service.updateInfo(record);
        return BaseBean.success(ResponseCode.SUCCESS);
    }

    /**
     * 查询车系详情
     * @param id 车系id
     * @return 车系详情
     */
    @GetMapping("/getSeriesDetail/{id}")
    @ApiOperation(value = "查询车系详情")
    @ApiImplicitParam(name = "id", value = "车系id", dataType = "int", required = true, defaultValue = "1")
    public BaseBean<CarSeriesVO> getSeriesDetail(@PathVariable Integer id) {
        return service.getSeriesDetail(id);
    }

    /**
     * 车系列表带条件查询(分页)
     * @param record 车系查询条件
     * @return 车系列表
     */
    @GetMapping("/getCarSeriesList")
    @ApiOperation(value = "车系列表带条件查询(分页)")
    @ApiImplicitParams({})
    public BaseBean<BasePageBean<CarSeriesVO>> getCarSeriesList(@RequestBody CarSeriesPagesBO record) {
        return service.getCarSeriesList(record);
    }

}
